package itheima.com.Test;

import java.io.*;
import java.util.ArrayList;

public class CookerTest8 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:\\a.txt"));
        Cooker c1 = new Cooker("夏语","25");
        Cooker c2 = new Cooker("刘兴","22");
        Cooker c3 = new Cooker("胡仁","23");

        ArrayList<Cooker> list1 = new ArrayList<>();
        list1.add(c1);
        list1.add(c2);
        list1.add(c3);

        oos.writeObject(list1);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("E:\\a.txt"));
        ArrayList<Cooker> list2 =(ArrayList<Cooker>) ois.readObject();
        for (Cooker cooker : list2) {
            System.out.println(cooker);
        }
        ois.close();
    }
}
